<template>
  <transition name="fade" mode="out-in">
    <div class="search">
      <van-search
        v-model="search"
        placeholder="搜索业务员姓名、手机或推荐码"
        show-action
        @search="onSearch"
      >
        <div slot="action" @click="onCancel" class="search-cancel">取消</div>
      </van-search>

      <van-list
        v-if="!isNoData"
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div
          v-for="item in list"
          :key="item"
          class="list-item"
        >
          <div class="list-title">
            <img src="@/assets/index/icon_salesman.png" style="border-radius: 50%;width: 36px;margin-right: 10px;">
            <div class="name">
              苏桂英
            </div>
          </div>
          <div class="list-code">
            TJM10101
          </div>
        </div>
      </van-list>

      <div class="no-data" v-else>
        <img src="@/assets/blank_illustrations.png">
        啊哦，没有搜索结果~
      </div>
    </div>
  </transition>
</template>

<script>
import { Button, NavBar, Search, List } from 'vant';
export default {
  components: {
    [Button.name]: Button,
    [NavBar.name]: NavBar,
    [Search.name]: Search,
    [List.name]: List,
  },
  data () {
    return {
      isNoData: true,
      search: '',
      list: [],
      loading: false,
      finished: false
    }
  },
  mounted() {

  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    onCancel() {
      this.$router.go(-1)
    },
    onSearch() {

    },
    onLoad() {
      // 异步更新数据
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }
        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 500);
    }
  },
}
</script>

<style scoped>
.search {
  height: 100vh;
  overflow: auto;
  background-color: #fff;
  color: #38393A;
}
.search-cancel {
  margin: 0 6px;
}
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
}
.list-title {
  display: flex;
  flex-direction: row;
  align-items: center;
}
.no-data {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: calc(100vh - 54px);
  color: #999999;
  font-size: 14px;
  line-height: 20px;
  background-color: #fff;
}
.no-data img {
  margin-bottom: 16px; 
  width: 252px;
}
</style>
